package win.smartown.app.gank.type;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import win.smartown.app.R;
import win.smartown.app.base.BaseActivity;
import win.smartown.app.gank.type.data.TypeDataActivity;
import win.smartown.app.util.JumpUtil;
import win.smartown.easyAdapter.ColorDivider;
import win.smartown.easyAdapter.EasyAdapter;
import win.smartown.easyAdapter.EasyViewHolder;

/**
 * Created by smartown on 2017/5/5 10:13.
 * Desc:
 */
public class TypeActivity extends BaseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setBaseView(R.layout.layout_recycler_view);

        final String[] types = getResources().getStringArray(R.array.type);

        RecyclerView recyclerView = findView(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new ColorDivider(Color.parseColor("#cccccc"), 1));
        recyclerView.setAdapter(new EasyAdapter(this) {

            @Override
            public int getItemLayout(int viewType) {
                return R.layout.item_type;
            }

            @Override
            public void onBindViewHolder(EasyViewHolder holder, int position) {
                final String type = types[position];
                holder.getTextView(R.id.text).setText(type.toUpperCase());
                holder.getView(R.id.text).setTag(type);
                holder.getView(R.id.text).setOnClickListener(TypeActivity.this);
            }

            @Override
            public int getItemCount() {
                return types.length;
            }
        });
    }

    @Override
    public void onClick(View v) {
        JumpUtil.startActivity(this, TypeDataActivity.class, (String) v.getTag());
    }
}
